<%@ page language="java" pageEncoding="UTF-8" %>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>

    <link rel="stylesheet" href="<%=path %>/css/common.css">
    <link rel="stylesheet" href="<%=path %>/css/main.css">
    <script src="<%=path %>/js/jquery-1.12.4.js"></script>
    <%--    <script src="<%=path %>/js/comonData.js"></script>--%>

    <title>Document</title>
    <style type="text/css">
        #id_img {
            width: 30px;
            height: 30px;
        }

    </style>
</head>
<body>
<div class="container">

    <div id="forms" class="mt10">
        <div class="box">
            <div class="box_border">
                <div class="box_top"><b class="pl15">增加学生</b></div>
                <div class="box_center">


                    <form name="form1" method="post" action="<%=path%>/addStudent" class="jqtransform">
                        <table class="form_table pt15 pb15" width="50%" border="0" cellpadding="0" cellspacing="0">

                            <tr>
                                <td class="td_right">学号：</td>
                                <td>
                                    <input type="text" required="required" onblur="check(this.value)" id="idNumber"
                                           name="id" class="input-text lh30" value="" size="40">
                                    <span id="nameExists" style="color: red"></span>
                                </td>
                            </tr>

                            <tr>
                                <td class="td_right">姓名：</td>
                                <td class="">
                                    <input type="text" name="name" required="required" class="input-text lh30"
                                           size="40">
                                </td>
                            </tr>

                            <tr>
                                <td class="td_right">性别：</td>
                                <td class="">
                                    <input type="radio" name="sex" value="男" checked>男
                                    <input type="radio" name="sex" value="女">女
                                </td>
                            </tr>


                            <tr>
                                <td class="td_right">身份证：</td>
                                <td class="">
                                    <input type="text" maxlength="18" id="card" name="card"
                                           class="input-text lh30" size="40">

                                </td>
                            </tr>

                            <tr>
                                <td class="td_right">联系电话：</td>
                                <td class="">
                                    <input type="text" maxlength="20" name="phone" class="input-text lh30"
                                           size="40">
                                </td>
                            </tr>


                            <tr>
                                <td class="td_right">学院：</td>
                                <td class="">
                                    <%--<input type="text" name="department" class="input-text lh30" size="40">--%>
                                    <select id="department" name="department" class="input-text lh30">
                                        <option selected disabled>请选择</option>
                                    </select>
                                </td>
                            </tr>

                            <tr>
                                <td class="td_right">班级：</td>
                                <td class="">
                                    <%-- <input type="text" name="banji" class="input-text lh30" size="40">--%>
                                    <select id="banji" name="banji" class="input-text lh30">
                                        <option selected disabled>请选择</option>
                                    </select>
                                </td>
                            </tr>

                            <tr>
                                <td class="td_right">&nbsp;</td>
                                <td class="">
                                    <input type="submit" name="button" class="btn btn82 btn_save2" value="新增">
                                    <input type="button" id="mback_btn"
                                           onclick="location.href='<%=path %>/studentList/1/10'" name="button"
                                           class="btn btn82 btn_res" value="返回">
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>


</div>
<script src="<%=path%>/js/layer.js"></script>
<script>
    if ("${msg}" !== "") {
        layer.msg("${msg}")
    }

    var department = document.getElementById("department");
    var banji = document.getElementById("banji");
    $.post("<%=path %>/getAllClasses", {}, function (resp) {
        console.log(resp)
        var dep = [];
        resp.forEach(function (item) {
            console.log(item)
            if (!dep.includes(item.xueYuan)) {
                dep.push(item.xueYuan)
                department.innerHTML += "<option>" + item.xueYuan + "</option>"
            }
            banji.innerHTML += "<option>" + item.banJi + "</option>";
        })
    })

    function check(id) {
        $.get("<%=path %>/studentExists?id="+id,function (resp) {
                console.log(resp)
            if(resp.code == 0){
                    $("#nameExists").text("用户已经存在")
            }
        })
    }
</script>
</body>
</html>
  